import java.io.IOException;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;

/**
 * @author xingzhiwen
 * @date 2021/9/14
 * @ddescription:
 */
public class SocketTcp01Client {
    public static void main(String[] args) throws IOException {
        //1.连接服务端(ip 端口
            //如果；连接成功，返回socket对象
        Socket socket = new Socket(InetAddress.getLocalHost(), 9999);
        System.out.println("客户端+socket返回 = " + socket.getClass());
        //连接上后，生成socket，通过socket。getoutputstream 得到和socket对象关联的输出流
        OutputStream outputStream = socket.getOutputStream();
        //通过输出流，写入数据到数据通道
        outputStream.write("helloworld".getBytes());
        //关闭流对象和socket，必须
        outputStream.close();
        socket.close();

        System.out.println("客户端结束");
    }
}
